<?php

namespace App\Http\Requests\Api;

class PlanRequest extends FormRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        switch ($this->route()->getName()) {
            case 'plans.store':
                return [
                    'title' => 'required|min:2|max:60',
                    'description' => 'sometimes|max:255',
                    'date' => 'required|date',
                    'address' => 'required|max:120',
                ];

            case 'plans.update':
                return [
                    'title' => 'sometimes|min:2|max:60',
                    'description' => 'sometimes|max:255',
                    'date' => 'sometimes|date',
                    'address' => 'sometimes|max:120',
                ];

            default:;
        }
    }

    public function messages(): array
    {
        return [
            'title.required' => '标题不能为空',
            'title.min' => '标题最小长度为2个字符',
            'title.max' => '标题最大长度为60个字符',
            'description.max' => '描述最大长度为255个字符',
            'date.required' => '拍摄时间不能为空',
            'date.date' => '拍摄时间格式不合法',
            'address.required' => '拍摄地点不能为空',
            'address.max' => '拍摄地点最大长度为120个字符',
            'path.required' => '路径不能为空',
            'path.url' => '路径不合法',
        ];
    }
}
